$(function () {
  //toolbar权限控制
  toolBarPermission()
  var editFlag = permissions.sys_menu_edit
  var delFlag =  permissions.sys_menu_del

  var options = {
    code: "menuId",
    parentCode: "parentId",
    uniqueId: "menuId",
    rootIdValue: "-1",
    expandAll: false,
    expandFirst: false,
    method: 'post',
    url: api + "/admin/menu/list",
    createUrl: api + "/pages/sysadm/menu/menuEdit",
    updateUrl: api + "/pages/sysadm/menu/menuEdit",
//		updateUrl: "/sysadm/menu/menuEdit.html",
    removeUrl: api + "/admin/menu/{id}",
    modalName: "菜单",
    showSearch: false,
    showRefresh: false,
    columns: [
      {
        field: 'selectItem',
        radio: true
      },
      {
        title: '菜单名称',
        field: 'name',
        width: '20%',
        formatter: function (value, row, index) {
          if ($.common.isEmpty(row.icon)) {
            return row.name;
          } else {
            return '<i class="' + row.icon
              + '"></i> <span class="nav-label">'
              + row.name + '</span>';
          }
        }
      },
      {
        field: 'sort',
        title: '排序',
        width: '15%',
        align: "left",
        formatter: function (value, row, index) {
          return value == null ? '-' : value
        }
      },
      {
        field: 'path',
        title: '组件路径',
        width: '15%',
        align: "left",
        formatter: function (value, row, index) {
          return $.table.tooltip(value);
        }
      },
      {
        title: '类型',
        field: 'type',
        width: '15%',
        align: "left",
        formatter: function (value, item, index) {
          if (item.type == '0') {
            return '<span class="label label-primary">菜单</span>';
          } else if (item.type == '1') {
            return '<span class="label label-warning">按钮</span>';
          }
        }
      },
      {
        field: 'permission',
        title: '权限标识',
        width: '15%',
        align: "left",
        formatter: function (value, row, index) {
          return $.table.tooltip(value);
        }
      },
      {
        title: '操作',
        width: '20%',
        align: "left",
        formatter: function (value, row, index) {
          var actions = [];
          if (editFlag) {
            actions.push('<a class="btn btn-success btn-xs " href="javascript:void(0)" onclick="$.operate.edit(\'' + row.menuId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
          }
          if (delFlag) {
            actions.push('<a class="btn btn-danger btn-xs " href="javascript:void(0)" onclick="$.operate.remove(\'' + row.menuId + '\')"><i class="fa fa-trash"></i>删除</a>');
          }
          return actions.join('');
        }
      }]
  };
  $.treeTable.init(options);
});